<?php
/**
 * 字符串相关的函数
 * 创建随机字符串
 * @param int $type 随机数的类型 1数字 2字母 3数字+字母
 * @param int $length 随机数的长度
 * @return string 返回字符串的类型
 */
function buildRandomString($type = 1,$length = 4){
    if ($type == 1){
        $chars = join("",range(0,9));
    }else if ($type = 2){
        $chars = join("",array_merge(range('a','z'),range('A','Z')));
    }else if ($type == 3){
        $chars = join("",array_merge(range('a','z'),range('A','Z'),range(0,9)));
    }
    if ($length >strlen($chars)){
        exit('字符串长度不够');
    }
    $chars = str_shuffle($chars);
    return substr($chars,0,$length);
}

/**
 * 生成唯一的字符串
 * @return string
 */
function getUniName(){
    return md5(uniqid(microtime(true),true));
}